package com.ly.controller;

import com.github.pagehelper.PageInfo;
import com.ly.bean.EasybuySeckillGoods;
import com.ly.service.SeckillGoodsService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.Date;

/**
 * @author 李岩
 * @date 2021/12/30-9:52
 * @describe
 */
@Controller
@RequestMapping("checkKill")
public class CheckKillController {

    private final Logger logger= LoggerFactory.getLogger(CheckKillController.class);
    private CheckKillController(){
        System.out.println("CheckKillController   的controller层");
    }

    @Reference(url = "dubbo://localhost:20887")
    private SeckillGoodsService seckillGoodsService;

    @RequestMapping("showAllKillProduct")
    public String showAllKillProduct(Integer pageNum, Model model){
        try {
            logger.info("查询所有的秒杀商品的申请列表 "+pageNum);
            PageInfo<EasybuySeckillGoods> pageInfo = seckillGoodsService.showAllKillProduct(pageNum);
            model.addAttribute("pageInfo",pageInfo);
            return "kill_list";
        } catch (Exception e) {
            logger.error("查询所有的秒杀商品的申请列表 出现异常 "+e);
        }
        return "error";
    }
    //管理员审核秒杀商品的状态
    @RequestMapping("confirmApplyKillGoods")
    public String confirmApplyKillGoods(EasybuySeckillGoods seckillGoods){

        try {
            seckillGoods.setCheckTime(new Date(new java.util.Date().getTime()));
            System.out.println("管理员审核秒杀商品的状态 修改为  "+seckillGoods);
            seckillGoodsService.updateByPrimaryKeySelective(seckillGoods);
            return "redirect:/checkKill/showAllKillProduct";
        } catch (Exception e) {
            logger.error("管理员审核秒杀商品的状态 出现异常 "+e);
        }
        return "error";
    }
}
